home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / text_utl / emedit20 / gotoline.fr_ / gotoline.fr
Text File  |  1995-09-04  |  8KB  |  265 lines

  1. VERSION 2.00
  2. Begin Form frmGotoLine 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Goto Line"
  5.    ClientHeight    =   1692
  6.    ClientLeft      =   216
  7.    ClientTop       =   2616
  8.    ClientWidth     =   5112
  9.    Height          =   2016
  10.    Left            =   168
  11.    LinkTopic       =   "Form2"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   1692
  15.    ScaleWidth      =   5112
  16.    Top             =   2340
  17.    Width           =   5208
  18.    Begin CommandButton cmdRemove 
  19.       Caption         =   "&Remove"
  20.       Height          =   312
  21.       Left            =   4140
  22.       TabIndex        =   12
  23.       Top             =   1260
  24.       Visible         =   0   'False
  25.       Width           =   852
  26.    End
  27.    Begin CommandButton cmdAdd 
  28.       Caption         =   "&Add"
  29.       Height          =   312
  30.       Left            =   4140
  31.       TabIndex        =   11
  32.       Top             =   900
  33.       Visible         =   0   'False
  34.       Width           =   852
  35.    End
  36.    Begin Frame Frame1 
  37.       Caption         =   "Go To &What"
  38.       Height          =   1152
  39.       Left            =   120
  40.       TabIndex        =   2
  41.       Top             =   60
  42.       Width           =   1332
  43.       Begin OptionButton optBookmark 
  44.          Caption         =   "&Bookmark"
  45.          Height          =   252
  46.          Left            =   60
  47.          TabIndex        =   4
  48.          Top             =   660
  49.          Width           =   1212
  50.       End
  51.       Begin OptionButton optLine 
  52.          Caption         =   "&Line"
  53.          Height          =   192
  54.          Left            =   60
  55.          TabIndex        =   3
  56.          Top             =   360
  57.          Value           =   -1  'True
  58.          Width           =   1212
  59.       End
  60.    End
  61.    Begin CommandButton cmdcancel 
  62.       Cancel          =   -1  'True
  63.       Caption         =   "Cancel"
  64.       Height          =   312
  65.       Left            =   4140
  66.       TabIndex        =   1
  67.       Top             =   540
  68.       Width           =   852
  69.    End
  70.    Begin CommandButton cmdOK 
  71.       Caption         =   "&OK"
  72.       Default         =   -1  'True
  73.       Height          =   312
  74.       Left            =   4140
  75.       TabIndex        =   0
  76.       Top             =   180
  77.       Width           =   840
  78.    End
  79.    Begin Frame frameBookmark 
  80.       Height          =   1152
  81.       Left            =   1560
  82.       TabIndex        =   8
  83.       Top             =   60
  84.       Width           =   2472
  85.       Begin ComboBox comboBookmark 
  86.          Height          =   288
  87.          Left            =   120
  88.          Sorted          =   -1  'True
  89.          TabIndex        =   10
  90.          Text            =   "comboBookmark"
  91.          Top             =   540
  92.          Width           =   2292
  93.       End
  94.       Begin Label Label2 
  95.          Caption         =   "B&ookmark Name"
  96.          Height          =   252
  97.          Left            =   120
  98.          TabIndex        =   9
  99.          Top             =   240
  100.          Width           =   1452
  101.       End
  102.    End
  103.    Begin Frame frameLine 
  104.       Height          =   1152
  105.       Left            =   1560
  106.       TabIndex        =   5
  107.       Top             =   60
  108.       Width           =   2472
  109.       Begin TextBox Text1 
  110.          Height          =   288
  111.          Left            =   180
  112.          TabIndex        =   7
  113.          Top             =   480
  114.          Width           =   1668
  115.       End
  116.       Begin Label Label1 
  117.          Caption         =   "Line &Number:"
  118.          Height          =   252
  119.          Left            =   180
  120.          TabIndex        =   6
  121.          Top             =   240
  122.          Width           =   1452
  123.       End
  124.    End
  125. End
  126. Option Explicit
  127.  
  128. Sub AddBookmark ()
  129.     ' If the bookmark already exists then don't do anything
  130.     Dim BookmarkName As String
  131.     BookmarkName = Trim$(comboBookmark.Text)
  132.     Dim BookmarkIndex As Long
  133.     For BookmarkIndex = 0 To frmMDI.ActiveForm.Text1.BookmarkCount - 1
  134.         If frmMDI.ActiveForm.Text1.BookmarkName(BookmarkIndex) = BookmarkName Then
  135.             Exit Sub
  136.         End If
  137.     Next
  138.  
  139.     'Don't allow blank bookmark names
  140.     If BookmarkName = "" Then Exit Sub
  141.  
  142.     'Now add the bookmark
  143.     '
  144.     'If there are any removed bookmarks then use them
  145.     For BookmarkIndex = 0 To frmMDI.ActiveForm.Text1.BookmarkCount - 1
  146.         If frmMDI.ActiveForm.Text1.BookmarkOffset(BookmarkIndex) < 0 Then
  147.             frmMDI.ActiveForm.Text1.BookmarkName(BookmarkIndex) = BookmarkName
  148.             frmMDI.ActiveForm.Text1.BookmarkOffset(BookmarkIndex) = frmMDI.ActiveForm.Text1.CaretOffset
  149.             Exit Sub
  150.         End If
  151.     Next
  152.     '
  153.     'There are not removed bookmarks so create a new one.
  154.     BookmarkIndex = frmMDI.ActiveForm.Text1.BookmarkCount
  155.     frmMDI.ActiveForm.Text1.BookmarkCount = frmMDI.ActiveForm.Text1.BookmarkCount + 1
  156.     frmMDI.ActiveForm.Text1.BookmarkName(BookmarkIndex) = BookmarkName
  157.     frmMDI.ActiveForm.Text1.BookmarkOffset(BookmarkIndex) = frmMDI.ActiveForm.Text1.CaretOffset
  158. End Sub
  159.  
  160. Sub cmdAdd_Click ()
  161.     AddBookmark
  162. End Sub
  163.  
  164. Sub cmdCancel_Click ()
  165.     Me.Hide
  166. End Sub
  167.  
  168. Sub cmdOK_Click ()
  169.     DoIt
  170.     Me.Hide
  171. End Sub
  172.  
  173. Sub cmdRemove_Click ()
  174.     RemoveBookmark
  175. End Sub
  176.  
  177. Sub DoIt ()
  178.    On Error GoTo SearchError
  179.     ' go to a line
  180.     If optLine.Value <> 0 Then
  181.         'Parse the users text into a long variable.
  182.         'On error jump to SearchError
  183.         Dim GoDestination As Long
  184.         GoDestination = CLng(Text1.Text)
  185.         Resume Next
  186.     
  187.         frmMDI.ActiveForm.Text1.CaretY = CLng(Text1.Text)
  188.  
  189.     ' go to a bookmark
  190.     Else
  191.         Dim BookmarkName As String
  192.         BookmarkName = Trim$(comboBookmark.Text)
  193.         Dim MarkIndex As Long
  194.         For MarkIndex = 0 To frmMDI.ActiveForm.Text1.BookmarkCount - 1
  195.           If frmMDI.ActiveForm.Text1.BookmarkName(MarkIndex) = BookmarkName Then
  196.             frmMDI.ActiveForm.Text1.CaretOffset = frmMDI.ActiveForm.Text1.BookmarkOffset(MarkIndex)
  197.             Exit For
  198.           End If
  199.         Next
  200.     End If
  201.  
  202. SearchError:
  203.     Resume Next
  204. End Sub
  205.  
  206. Sub FillBookmarkList ()
  207.     Dim i As Long
  208.     comboBookmark.Clear
  209.     For i = 0 To frmMDI.ActiveForm.Text1.BookmarkCount - 1
  210.         If 0 <= frmMDI.ActiveForm.Text1.BookmarkOffset(i) Then
  211.             comboBookmark.AddItem frmMDI.ActiveForm.Text1.BookmarkName(i)
  212.         End If
  213.     Next
  214.     If 0 < comboBookmark.ListCount Then
  215.         comboBookmark.ListIndex = 0
  216.     Else
  217.         comboBookmark.ListIndex = -1
  218.     End If
  219. End Sub
  220.  
  221. Sub Form_Activate ()
  222.     CenterFormInApp Me
  223.     FillBookmarkList
  224. End Sub
  225.  
  226. Sub Form_Load ()
  227.     frameLine.ZOrder
  228. End Sub
  229.  
  230. Sub optBookmark_Click ()
  231.     cmdRemove.Visible = True
  232.     frameBookmark.ZOrder
  233.     cmdAdd.Visible = True
  234. End Sub
  235.  
  236. Sub optLine_Click ()
  237.     cmdRemove.Visible = False
  238.     cmdAdd.Visible = False
  239.     frameLine.ZOrder
  240. End Sub
  241.  
  242. Sub RemoveBookmark ()
  243.     ' If the bookmark doesn't exist then don't do anything
  244.     Dim BookmarkName As String
  245.     BookmarkName = Trim$(comboBookmark.Text)
  246.     Dim BookmarkIndex As Long
  247.     For BookmarkIndex = 0 To frmMDI.ActiveForm.Text1.BookmarkCount - 1
  248.         If frmMDI.ActiveForm.Text1.BookmarkName(BookmarkIndex) = BookmarkName Then
  249.             GoTo BookmarkExists:
  250.         End If
  251.     Next
  252.     Exit Sub
  253.  
  254. BookmarkExists:
  255.     'Now remove the bookmark
  256.     If BookmarkIndex = frmMDI.ActiveForm.Text1.BookmarkCount - 1 Then
  257.         frmMDI.ActiveForm.Text1.BookmarkCount = frmMDI.ActiveForm.Text1.BookmarkCount - 1
  258.     Else
  259.         frmMDI.ActiveForm.Text1.BookmarkName(BookmarkIndex) = "Removed"
  260.         frmMDI.ActiveForm.Text1.BookmarkOffset(BookmarkIndex) = -1
  261.     End If
  262.     FillBookmarkList
  263. End Sub
  264.  
  265.